package lzm.factory;

import lzm.spring.config.Inteceptor;
import org.springframework.beans.factory.FactoryBean;

/**
 * 接口实例工厂，这里主要是用于提供接口的实例对象
 * @author lichuang
 */
public class ServiceFactory<T> implements FactoryBean<T> {

    private Class<T> interfaceType;

    public ServiceFactory(Class<T> interfaceType) {
        this.interfaceType = interfaceType;
    }

    @Override
    public T getObject() throws Exception {
        //这里主要是创建接口对应的实例，便于注入到spring容器中
        return (T) new Inteceptor().createCGLBProxy(interfaceType);
    }

    @Override
    public Class<T> getObjectType() {
        return interfaceType;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}